<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>孩子ABO血型计算器</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f0f8ff; /* 浅蓝色背景 */
            margin: 0;
            padding: 0;
            text-align: center;
        }

        h1 {
            color: #ff69b4; /* 粉色标题 */
            margin-top: 20px;
        }

        .container {
            background-color: #ffe4e1; /* 粉色背景 */
            border-radius: 10px;
            padding: 30px;
            margin: 20px auto;
            width: 80%;
            max-width: 500px;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
        }

        label {
            font-weight: bold;
            margin-right: 10px;
            color: #ff1493; /* 深粉色 */
        }

        select {
            padding: 10px;
            border: 1px solid #ff69b4; /* 粉色边框 */
            border-radius: 5px;
            background-color: #fff;
            font-size: 16px;
            margin-bottom: 15px;
        }

        button {
            background-color: #add8e6; /* 浅蓝色按钮 */
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s;
            margin-top: 15px;
        }

        button:hover {
            background-color: #87ceeb; /* 浅蓝色按钮悬停效果 */
        }

        #result {
            margin-top: 20px;
            font-size: 20px;
            color: #ff1493; /* 深粉色 */
        }

        .footer {
            margin-top: 30px;
            font-size: 14px;
            color: #666;
        }
    </style>
    <script>
        function compute() {
            let parent1 = document.querySelector("#x1").value;
            let parent2 = document.querySelector("#x2").value;
            let result = "";
            let possibleBloodTypes = getPossibleBloodTypes(parent1, parent2);

            if (possibleBloodTypes.length === 0) {
                result = "无法确定孩子的血型。";
            } else {
                result = "孩子的可能血型为：" + possibleBloodTypes.join(", ");
            }

            document.querySelector("#result").textContent = result;
        }

        function getPossibleBloodTypes(parent1, parent2) {
            let bloodTypeCombinations = {
                'a': ['a', 'o'],
                'b': ['b', 'o'],
                'ab': ['a', 'b'],
                'o': ['o']
            };

            let possibleTypes = [];
            bloodTypeCombinations[parent1].forEach(gene1 => {
                bloodTypeCombinations[parent2].forEach(gene2 => {
                    if (gene1 === 'o' && gene2 === 'o') {
                        possibleTypes.push(gene1 + gene2);
                    } else {
                        possibleTypes.push(gene1 === 'o' ? gene2 : gene1 === gene2 ? gene1 : 'ab');
                        possibleTypes.push(gene1 === 'o' ? gene2 : gene1 === gene2 ? gene1 : 'o');
                    }
                });
            });

            return Array.from(new Set(possibleTypes)).map(type => type.toUpperCase());
        }
    </script>
</head>

<body>
    <h1>孩子ABO血型计算器</h1>
    <div class="container">
        <div>
            <label for="x1">你的血型：</label>
            <select name="" id="x1">
                <option value="a">A</option>
                <option value="b">B</option>
                <option value="ab">AB</option>
                <option value="o">O</option>
            </select>
        </div>
        <div>
            <label for="x2">你配偶的血型：</label>
            <select name="" id="x2">
                <option value="a">A</option>
                <option value="b">B</option>
                <option value="ab">AB</option>
                <option value="o">O</option>
            </select>
        </div>
        <button onclick="compute()">查看结果</button>
        <div id="result">测试结果：</div>
    </div>
    <div class="footer">©2024 版权由@Z-NM-0提供</div>
</body>

</html>
